
export default {
  namespaced: true, // 必须要划分空间，开发者必须要保证模块名是属性不一样
  state: {
    age: 20
  },
  getters: { // 类似计算属性
    myAge(state) {
      console.log('getters -> myAge');
      return state.age + 11;
    }
  },
  mutations: { // 通过 $store.commit 触发该对象函数, 更改 state 的状态
    syncAdd(state, payload) {
      console.log('moduleA syncAdd mutations', payload)
      state.age += payload.age;
    },
    asyncMinus(state, payload) {
      console.log('moduleA asyncMinus mutations', payload)
      state.age -= payload.age;
    }
  },
  actions: { // 通过 $store.dispatch 触发该对象函数
    syncAdd({ commit }, payload) {
      setTimeout(() => {
        console.log('moduleA actions syncAdd setTimeout')
        commit('syncAdd', payload);
      }, 3000);
    },
    asyncMinus({ commit }, payload) {
      setTimeout(() => {
        console.log('moduleA actions asyncMinus setTimeout')
        commit('asyncMinus', payload);
      }, 3000);
    }
  }
}